local skel = fk.CreateSkill {
  name = "emo__qianmian",
}

Fk:loadTranslationTable{
  ["emo__qianmian"] = "千面",
  [":emo__qianmian"] = "每轮开始时，你获得三个<a href='emo__qianzhuan_href'>“千转”</a>技能（至多拥有三个）。每当你受到伤害后，你可以移去一个“千转”技能，摸两张牌。",

  ["emo__qianzhuan_href"] = "“千转”技能是消耗随机、转化为随机牌的转化技。发动“千转”技能后，随机重铸为其他转化技。",
  ["#emo__qianmian-delete"] = "千面：你可以移去一个“千转”，摸2张牌",
  ["#emo__qianzhuan-give"] = "千转：你可以将转化的这些牌交给一名其他角色",
}


--- 获取千转技能的序号
---@param name string @ 技能名
---@return number? @ 返回nil则说明不是千转技能
local function getQZindex(name)
  if Fk.skills[name] == nil then return nil end
  if string.sub(name, 1, 3) == "emo" then
    local startPos = 4
    local endPos = string.find(name, "_", startPos, true)
    if endPos then
      local subStr = string.sub(name, startPos, endPos - 1)
      if string.sub(name, endPos, -1) ~= "__qianzhuan" then return nil end
      local num = tonumber(subStr)
      if num then
        return num
      end
    end
  end
  return nil
end

--- 获得角色拥有的千转技能
---@param player Player
local getQZSkills = function (player)
  return table.map(table.filter(player.player_skills, function (skill)
    return getQZindex(skill.name) ~= nil
  end), Util.NameMapper)
end

--- 单卡转化类消耗
local onecard_cost = {"slash", "jink", "slash_jink", "red", "black", "basic", "trick", "equip", "nonbasic", "spade", "heart", "club", "diamond",
 "odd", "letter" }

--- 无卡转化类消耗
local zerocard_cost = {"0", "allhand", "recastall", "showcolorhand", "turnover", "losehp", "swaphand", "draw1", "draw2", "recover", "chain",
 "lightningjudge", "moveinboard" }

--- 多卡转化类消耗
local multicard_cost = { "diffcolor2", "samecolor2", "sametype2", "samesuit2", "sum13", "halfhand" }

--- 创建一个千转技能
---@param room Room
---@return string? @ 返回创建的技能
local function createQZSkill(room)
  local exists = {}
  local skill
  local tag = room:getBanner("emo__qianzhuan_record") or {}
  for i = 1, 50 do
    local skill_name = "emo" .. i .. "__qianzhuan"
    if Fk.skills[skill_name] == nil then break end
    if tag[skill_name] == nil then
      skill = skill_name
      break
    else
      table.insert(exists, skill_name)
    end
  end
  if skill == nil then
    if #exists == 0 then return nil end
    return table.random(exists) -- 如果所有技能都被记录过，干脆返回已记录的技能
  end
  -- 先决定转化的牌名
  local info = {}
  local card_name = "slash"
  if #exists == 0 or math.random() < 0.1 then
    -- 常用杀闪 第一次必出
    card_name = table.random({ "slash", "jink" })
  else
    local names = Fk:getAllCardNames("btd")
    local extra_names = { -- 无视禁表的额外选择
      "stab__slash",
      "unexpectation", "foresight", "bogus_flower", "sincere_treat", "looting", "drowning",
    }
    local ban_names = {"borrow_arrows"} -- 草拟大爷
    for _, name in ipairs(extra_names) do
      if Fk.all_card_types[name] ~= nil then
        table.insertIfNeed(names, name)
      end
    end
    for _, name in ipairs(ban_names) do
      table.removeOne(names, name)
    end
    table.shuffle(names)
    card_name = table.random(names)
  end
  local card_copy = Fk.all_card_types[card_name]
  if card_copy == nil then return nil end
  info.card = card_name

  -- 必须选择单卡消耗的情况
  local must_single = card_copy.sub_type == Card.SubtypeDelayedTrick or card_copy.name == "unexpectation"
  local cost_list = {"0"}
  if must_single or math.random() < 0.7 then -- 需要选牌的消耗
    cost_list = table.simpleClone(onecard_cost)
    if not must_single then
      table.insertTable(cost_list, multicard_cost)
    end
  else -- 不选牌消耗
    cost_list = table.simpleClone(zerocard_cost)
  end
  --- 转化消耗不能与转化牌牌名相同
  for i = #cost_list, 1, -1 do
    if string.find(cost_list[i], card_name) then
      table.remove(cost_list, i)
    end
  end
  local cost = table.random(cost_list) -- 卡牌消耗
  info.cost = cost

  -- 特殊效果
  local special_rat = 0.8
  if table.contains(multicard_cost, cost) then special_rat = special_rat - 0.3 end -- 多牌转化更高概率获得特殊效果
  if math.random() > special_rat then
    local buffs = {"kongchengDraw", "injureRecover"}
    local hasRealCard = (cost == "allhand" or not table.contains(zerocard_cost, cost))
    -- 非被动即时牌
    local immediacy = (not card_copy.is_passive) and card_copy.sub_type ~= Card.SubtypeDelayedTrick
    if hasRealCard then
      table.insertTable(buffs, {"giveThisCard", "permanent"})
      -- 结算后使用转化的装备牌
      if card_copy.sub_type ~= Card.SubtypeDelayedTrick and not table.contains({"slash", "jink", "slash_jink", "trick", "basic"}, cost) then
        table.insert(buffs, "useEquip")
      end
    end
    if immediacy then
      table.insertTable(buffs, {"additionalEffect", "allDraw"})
      -- 废案。没法在before_use里增减目标，只因此时useCard事件还未产生
      if card_copy.multiple_targets then
        --table.insert(buffs, "removeTarget")
      else
        --table.insert(buffs, "addTarget")
      end
      if card_copy.is_damage_card then
        table.insertTable(buffs, {"additionalDamage", "damagedDiscard"})
      end
      if card_copy.is_damage_card or card_copy:isCommonTrick() then
        table.insert(buffs, "disresponsive")
      end
      if table.contains({"peach", "ex_nihilo", "foresight"}, card_copy.name) then -- 有福同享
        table.insert(buffs, "targetAllPlayer")
      end
      if table.contains({"amazing_grace", "god_salvation", "certamen"}, card_copy.name) then -- 超级五谷
        table.insert(buffs, "crazyGrace")
      end
      if card_copy.multiple_targets then
        table.insert(buffs, "randomTarget") -- 随机目标
      end
    end
    if #buffs > 0 then
      info.buff = table.random(buffs)
    end
  end

  tag[skill] = info
  room:setBanner("emo__qianzhuan_record", tag)
  return skill
end

--- 获取千转技能信息，可能无
---@param name string @ 技能名
---@return table?
local getQZInfo = function (name)
  local tag = Fk:currentRoom():getBanner("emo__qianzhuan_record") or {}
  return tag[name]
end

--- 获取千转技能描述
---@param skill string @ 技能名
---@return string
local function getQZDesc(skill)
  local info = getQZInfo(skill)
  if info == nil then return "" end
  local card_name, cost = info.card, info.cost
  local name_trans = Fk:translate(card_name)
  local arg2 = ""
  if table.contains(zerocard_cost, cost) then
    arg2 = "视为使用或打出【" .. name_trans .. "】"
  else
    arg2 = "当【" .. name_trans .. "】使用或打出"
  end
  local arg1 = cost
  if Fk.all_card_types[cost] ~= nil then
    arg1 = "将一张【" .. Fk:translate(cost) .. "】"
  else
    local desc_map = {
      ["red"] = "将一张红色牌",
      ["black"] = "将一张黑色牌",
      ["slash_jink"] = "将一张【杀】或【闪】",
      ["odd"] = "将一张奇数牌",
      ["letter"] = "将一张字母牌",
      ["spade"] = "将一张♠牌",
      ["heart"] = "将一张<font color='red'>♥</font>牌",
      ["club"] = "将一张♣牌",
      ["diamond"] = "将一张<font color='red'>♦</font>牌",
      ["basic"] = "将一张基本牌",
      ["trick"] = "将一张锦囊牌",
      ["equip"] = "将一张装备牌",
      ["nonbasic"] = "将一张非基本牌",

      ["sum13"] = "将点数和为13的牌",
      ["halfhand"] = "至少半数手牌",
      ["diffcolor2"] = "将两张不同的颜色牌",
      ["samecolor2"] = "将两张相同颜色牌",
      ["sametype2"] = "将两张相同类型牌",
      ["samesuit2"] = "将两张相同花色牌",

      ["allhand"] = "将所有手牌",
      ["recastall"] = "重铸所有牌",
      ["showcolorhand"] = "展示相同颜色的所有手牌",
      ["turnover"] = "翻面",
      ["losehp"] = "失去1点体力",
      ["draw1"] = "摸1张牌",
      ["draw2"] = "摸2张牌",
      ["recover"] = "回复1点体力",
      ["chain"] = "横置",
      ["swaphand"] = "与手牌不大于你的1名角色交换手牌",
      ["0"] = "",
      ["lightningjudge"] = "进行【闪电】判定",
      ["moveinboard"] = "移动你场上一张牌",
    }
    arg1 = desc_map[cost] or arg1
  end
  local arg3 = ""
  local buff = info.buff
  if buff then
    local desc_map = {
      ["kongchengDraw"] = "结算后若你没有手牌则摸两张牌",
      ["injureRecover"] = "结算后若你体力值不大于1则回复1点体力",
      ["permanent"] = "此技能使用后不会重铸",
      ["giveThisCard"] = "结算后可将转化牌交给一名其他角色",
      ["useEquip"] = "结算后你随机使用一张被转化的装备牌",
      ["additionalEffect"] = "额外结算一次",
      ["allDraw"] = "结算后令所有目标各摸一张牌",
      --["removeTarget"] = "可减少一个目标",
      --["addTarget"] = "可增加一个目标",
      ["additionalDamage"] = "基础伤害+1",
      ["damagedDiscard"] = "受到此牌伤害的角色须弃一张牌",
      ["disresponsive"] = "不可响应",
      ["targetAllPlayer"] = "指定所有角色为目标",
      ["crazyGrace"] = "额外结算两次且不可抵消",
      ["randomTarget"] = "随机指定目标",
    }
    arg3 = "，".. desc_map[buff] or buff
  end
  return "你可以" .. arg1 .. arg2 .. arg3 .."。"
end

--- 每轮开始时，获得三个千转技能
skel:addEffect(fk.RoundStart, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and #getQZSkills(player) < 3
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local x = 3 - #getQZSkills(player)
    for _ = 1, x do
      local skill = createQZSkill(room)
      if not skill then break end
      room:handleAddLoseSkills(player, skill)
    end
  end,
})

-- 收到伤害后，可以移去一个千转技能，摸牌
skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and #getQZSkills(player) > 0 and target == player
  end,
  on_cost = function (self, event, target, player, data)
    local skills = getQZSkills(player)
    local choices = table.map(skills, function (s) return getQZDesc(s) end)
    table.insert(choices, "Cancel")
    local choice = player.room:askToChoice(player, {
      skill_name = skel.name, choices = choices, prompt = "#emo__qianmian-delete"
    })
    local index = table.indexOf(choices, choice)
    if choice ~= "Cancel" and index > 0 then
      local skill = skills[index]
      event:setCostData(self, skill)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-".. event:getCostData(self))
    if not player.dead then
      player:drawCards(2, skel.name)
    end
  end,
})

--- 以千转转化的牌无次数限制
--[[
skel:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card)
    if card and type(card.skillNames) == "table" then
      for _, name in ipairs(card.skillNames) do
        if getQZindex(name) ~= nil then
          return true
        end
      end
    end
  end,
})
--]]


--- 选牌转化的规则
---@param self ViewAsSkill
---@param player Player
---@param to_select integer
---@param selected integer[]
local function card_filterQZ (self, player, to_select, selected)
  local info = getQZInfo(self.name)
  if info == nil then return false end
  local card = Fk:getCardById(to_select)
  local cost = info.cost
  if table.contains(zerocard_cost, cost) then return false end -- 0牌消耗，不用选牌
  if cost == "sum13" then -- 和为13
    local sum = card.number
    for _, id in ipairs(selected) do
      sum = sum + Fk:getCardById(id).number
    end
    return sum <= 13
  elseif cost == "halfhand" then -- 选手牌就行
    return table.contains(player:getCardIds("h"), to_select)
  elseif string.sub(cost, -1, -1) == "2" then -- 两张选牌
    if #selected == 0 then return true end
    if #selected == 1 then
      local first = Fk:getCardById(selected[1])
      if cost == "diffcolor2" then
        return first.color ~= card.color
      elseif cost == "samecolor2" then
        return first.color == card.color
      elseif cost == "sametype2" then
        return first.type == card.type
      elseif cost == "samesuit2" then
        return first.suit == card.suit
      end
    end
  elseif #selected == 0 then -- 单张选牌
    if Fk.all_card_types[cost] ~= nil then
      return card.trueName == cost
    elseif table.contains({"spade", "heart", "club", "diamond"}, cost) then
      return card:getSuitString() == cost
    elseif table.contains({"basic", "trick", "equip"}, cost) then
      return card:getTypeString() == cost
    elseif cost == "nonbasic" then
      return card.type ~= Card.TypeBasic
    elseif cost == "red" or cost == "black" then
      return card:getColorString() == cost
    elseif cost == "odd" then
      return card.number % 2 == 1
    elseif cost == "letter" then
      return table.contains({ 1, 11, 12, 13 }, card.number)
    elseif cost == "slash_jink" then
      return card.trueName == "slash" or card.trueName == "jink"
    end
  end
  return false
end

--- 转化为什么牌
---@param self ViewAsSkill
---@param player Player
---@param cards integer[]
---@return Card?
local function view_asQZ(self, player, cards)
  local info = getQZInfo(self.name)
  if info == nil then return nil end
  local card_name, cost = info.card, info.cost
  local card = Fk:cloneCard(card_name)
  card.skillName = self.name
  if table.contains(zerocard_cost, cost) then
    if cost == "allhand" then
      card:addSubcards(player:getCardIds("h"))
    end
    return card
  elseif #cards > 0 then
    card:addSubcards(cards)
    if table.contains(onecard_cost, cost) then
      if #cards == 1 then
        return card
      end
    elseif table.contains(multicard_cost, cost) then
      if string.sub(cost, -1, -1) == "2" then
        if #cards == 2 then
          return card
        end
      elseif cost == "sum13" then
        local sum = 0
        for _, id in ipairs(cards) do
          sum = sum + Fk:getCardById(id).number
        end
        if sum == 13 then
          return card
        end
      elseif cost == "halfhand" then
        if #cards >= math.ceil(player:getHandcardNum() / 2) then
          return card
        end
      end
    end
  end
end

--- 使用前执行一些内容
---@param player ServerPlayer @ 使用者
---@param skill string @ 使用的技能
---@param use UseCardDataSpec
local function before_useQZ(player, skill, use)
  local room = player.room
  local cost = getQZInfo(skill).cost
  if cost == "turnover" then
    player:turnOver()
  elseif cost == "losehp" then
    room:loseHp(player, 1, skill)
  elseif cost == "recastall" then
    room:recastCard(player:getCardIds("he"), player, skill)
  elseif cost == "showcolorhand" then
    player:showCards(player:getCardIds("h"))
  elseif string.sub(cost, 1, 4) == "draw" then
    local num = tonumber(string.sub(cost, -1, -1))
    if num then
      player:drawCards(num, skill)
    end
  elseif cost == "recover" then
    room:recover { num = 1, skillName = skill, who = player, recoverBy = player }
  elseif cost == "chain" then
    player:setChainState(true)
  elseif cost == "swaphand" then
    local targets = table.filter(room:getOtherPlayers(player), function (p)
      return p:getHandcardNum() <= player:getHandcardNum()
    end)
    if #targets > 0 then
      local to = targets[1]
      if #targets > 1 then
        to = room:askToChoosePlayers(player, {
          min_num = 1, max_num = 1, skill_name = skill, cancelable = false, targets = targets,
          prompt = "请与手牌不大于你的1名角色交换手牌",
        })[1]
      end
      room:swapAllCards(player, {player, to}, skill, "h")
    end
  elseif cost == "moveinboard" then
    local targets = table.filter(room:getOtherPlayers(player), function (p)
      return player:canMoveCardsInBoardTo(p)
    end)
    if #targets > 0 then
      local to = targets[1]
      if #targets > 1 then
        to = room:askToChoosePlayers(player, {
          min_num = 1, max_num = 1, skill_name = skill, cancelable = false, targets = targets,
          prompt = "选择1名角色，将你场上1张牌移动至其区域",
        })[1]
      end
      room:askToMoveCardInBoard(player, {
        target_one = player, target_two = to, skill_name = skill, move_from = player,
      })
    end
  elseif cost == "lightningjudge" then
    local judge = {
      who = player,
      reason = "lightning",
      pattern = ".|2~9|spade",
    }
    room:judge(judge)
    if judge:matchPattern() then
      room:damage{
        to = player,
        damage = 3,
        damageType = fk.ThunderDamage,
        skillName = "lightning_skill",
      }
    end
  end

  local buff = getQZInfo(skill).buff
  if buff == "additionalEffect" then
    use.additionalEffect = (use.additionalEffect or 0) + 1
  elseif buff == "removeTarget" then
    -- 这个没法做
  elseif buff == "addTarget" then
    -- 这个没法做
  elseif buff == "additionalDamage" then
    use.additionalDamage = (use.additionalDamage or 0) + 1
  elseif buff == "disresponsive" then
    use.disresponsiveList = table.simpleClone(room.players)
  elseif buff == "targetAllPlayer" then
    if use.tos then
      use.tos = table.simpleClone(room.alive_players)
    end
  elseif buff == "randomTarget" then
    if use.tos then
      local all = table.filter(room.alive_players, function(p) return
      not use.from:isProhibited(p, use.card) and use.card.skill:modTargetFilter(use.from, p, {}, use.card) end)
      if #all > 1 then
        use.tos = table.random(all, math.random(2, #all))
      end
    end
  elseif buff == "crazyGrace" then
    use.additionalEffect = (use.additionalEffect or 0) + 2
    use.unoffsetableList = table.simpleClone(room.players)
  end
end

--- 使用后执行一些内容
---@param player ServerPlayer
---@param skill string
---@param use UseCardData|RespondCardData
local function after_useQZ(player, skill, use)
  local room = player.room
  local info = getQZInfo(skill)
  if player.dead or info == nil then return end
  local buff = info.buff
  if buff == "giveThisCard" then
    local cards = room:getSubcardsByRule(use.card, {Card.DiscardPile}) -- 此时使用事件结束，牌已进入弃牌堆
    if #cards > 0 then
      local to = room:askToChoosePlayers(player, {
        min_num = 1, max_num = 1, skill_name = skill, cancelable = true, targets = room:getOtherPlayers(player),
        prompt = "#emo__qianzhuan-give",
      })[1]
      if to then
        room:obtainCard(to, cards, true, fk.ReasonGive, player, skill)
      end
    end
  elseif buff == "allDraw" then
    if use and type(use.tos) == "table" then
      local tos = table.simpleClone(use.tos)
      room:sortByAction(tos)
      room:doIndicate(player, tos)
      for _, to in ipairs(tos) do
        if not to.dead then
          to:drawCards(1, skill)
        end
      end
    end
  elseif buff == "damagedDiscard" then
    local tos = {}
    if use.damageDealt then
      for to, _ in pairs(use.damageDealt) do
        table.insert(tos, to)
      end
    end
    room:sortByAction(tos)
    room:doIndicate(player, tos)
    for _, to in ipairs(tos) do
      if not to.dead then
        room:askToDiscard(to, {min_num = 1, max_num = 1, skill_name = skill, cancelable = false, include_equip = true})
      end
    end
  elseif buff == "kongchengDraw" then
    if player:isKongcheng() then
      player:drawCards(2, skill)
    end
  elseif buff == "injureRecover" then
    if player.hp <= 1 then
      room:recover { num = 1, skillName = skill, who = player, recoverBy = player }
    end
  elseif buff == "useEquip" then
    local cards = room:getSubcardsByRule(use.card, {Card.DiscardPile})
    table.shuffle(cards)
    for _, id in ipairs(cards) do
      local card = Fk:getCardById(id)
      if card.type == Card.TypeEquip and player:canUseTo(card, player) then
        room:useCard{ from = player, tos = {player}, card = card }
        break
      end
    end
  end
end

--- 能否使用千转技能
---@param skill string @ 技能名
---@param player Player @ 使用者
---@return boolean
local function canUseQZ(skill, player)
  local info = getQZInfo(skill)
  if info == nil then return false end
  local card_name, cost = info.card, info.cost
  local card = Fk:cloneCard(card_name)
  card:setVSPattern(skel.name, player, ".")
  if cost == "allhand" then
    card:addSubcards(player:getCardIds("h"))
  end
  local pat = Fk.currentResponsePattern
  if pat then
    if not Exppattern:Parse(Fk.currentResponsePattern):match(card) then return false end
  else
    if not player:canUse(card) or player:prohibitUse(card) then return false end
  end
  -- 单牌和多牌转化至少有一张牌
  if table.contains(onecard_cost, cost) or table.contains(multicard_cost, cost) then
    if player:isNude() then return false end
  end
  -- 特殊判定条件
  if cost == "allhand" or cost == "halfhand" then
    return not player:isKongcheng()
  elseif cost == "recastall" then
    return not player:isNude()
  elseif cost == "showcolorhand" then
    local hand = player:getCardIds("h")
    return #hand > 0 and table.every(hand, function (id) return Fk:getCardById(id).color == Fk:getCardById(hand[1]).color end)
  elseif cost == "losehp" then
    return player.hp > 0
  elseif cost == "recover" then
    return player:isWounded()
  elseif cost == "chain" then
    return not player.chained
  elseif cost == "swaphand" then
    return table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and p:getHandcardNum() <= player:getHandcardNum()
    end) ~= nil
  elseif cost == "moveinboard" then
    return table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and player:canMoveCardsInBoardTo(p)
    end) ~= nil
  end
  -- 无特殊情况都能使用
  return true
end


local ret = {}
table.insert(ret, skel)

for i = 1, 50 do
  local skill_name = "emo" .. i .. "__qianzhuan"
  local skel_copy = fk.CreateSkill {
    name = skill_name,
    dynamic_desc = function (self, player, lang)
      return getQZDesc(self.name)
    end,
    dynamic_name = function (self, player, lang)
      local info = getQZInfo(self.name)
      if info == nil then return self.name end
      local card_name = info.card
      local nameAbbr = Fk:translate(card_name, "zh_CN")
      local len = nameAbbr:len()
      if len == 1 then
        nameAbbr = "转"..nameAbbr
      else
        nameAbbr = string.sub(nameAbbr, 1, 6)
      end
      return nameAbbr
    end,
  }

  Fk:loadTranslationTable{
    [skill_name] = "千转",
    [":"..skill_name] = "千转".. i .. "号",
  }

  skel_copy:addEffect("viewas", {
    pattern = ".|.|.|.|.|basic,trick",
    prompt = function (self, player, selected_cards, selected)
      return getQZDesc(self.name)
    end,
    card_filter = card_filterQZ,
    view_as = view_asQZ,
    before_use = function (self, player, use)
      local info = getQZInfo(self.name)
      if info == nil then return "" end
      local room = player.room
      room:invalidateSkill(player, self.name) -- 暂时封印技能，防止插结
      before_useQZ(player, self.name, use)
    end,
    after_use = function (self, player, use)
      player.room:validateSkill(player, self.name)
      local info = getQZInfo(self.name)
      if info and info.buff == "permanent" then return end -- 持恒，不重铸此技能
      if not player:hasSkill(self.name, true) then return end -- 如果没有此技能，则无法重铸
      player.room:handleAddLoseSkills(player, "-" .. self.name)
      after_useQZ(player, self.name, use)
      if player.dead then return end
      local new = createQZSkill(player.room)
      if new then
        player.room:handleAddLoseSkills(player, new)
      end
    end,
    enabled_at_play = function (self, player)
      return canUseQZ(self.name, player)
    end,
    enabled_at_response = function (self, player, response)
      return canUseQZ(self.name, player)
    end,
  })


  table.insert(ret, skel_copy)
end



return ret
